#!/bin/bash

#set gpu
adb shell "echo 1 > /sys/class/kgsl/kgsl-3d0/force_clk_on"
adb shell "echo 10000000 > /sys/class/kgsl/kgsl-3d0/idle_timer"
adb shell "echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor"
adb shell "echo 710000000 > /sys/class/kgsl/kgsl-3d0/gpuclk"

#set cpu work mode
#adb shell "echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
#adb shell "echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor"
#adb shell "echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor"
#adb shell "echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"
#adb shell "echo performance > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor"
#adb shell "echo performance > /sys/devices/system/cpu/cpu5/cpufreq/scaling_governor"
#adb shell "echo performance > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor"
#adb shell "echo performance > /sys/devices/system/cpu/cpu7/cpufreq/scaling_governor"

current_time=`adb shell date "+%y_%m_%d_%H_%M_%S"`
mkdir $current_time

#exec 1>./$current_time/system_info_$current_time.csv
echo "nowtime,gpucurfreq,gpu_load,cpu0curfreq,cpu1curfreq,cpu2curfreq,cpu3curfreq,cpu4curfreq,cpu5curfreq,cpu6curfreq,cpu7curfreq,fps,battery_capacity,user_cpu_usage,system_cpu_usage,total_cpu_usage" &> ./$current_time/system_info_$current_time.csv

isToRunning=true
trap "isToRunning=false" SIGINT
while $isToRunning
do 
	nowtime=`adb shell date "+%y_%m_%d_%H_%M_%S"`
	gpucurfreq=`adb shell cat /sys/class/kgsl/kgsl-3d0/devfreq/cur_freq` 
	cpu0curfreq=`adb shell cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq`
	cpu1curfreq=`adb shell cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq`
	cpu2curfreq=`adb shell cat /sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq`
	cpu3curfreq=`adb shell cat /sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq`
	cpu4curfreq=`adb shell cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq`
	cpu5curfreq=`adb shell cat /sys/devices/system/cpu/cpu5/cpufreq/scaling_cur_freq`
	cpu6curfreq=`adb shell cat /sys/devices/system/cpu/cpu6/cpufreq/scaling_cur_freq`
	cpu7curfreq=`adb shell cat /sys/devices/system/cpu/cpu7/cpufreq/scaling_cur_freq`

    echo "$nowtime,$gpucurfreq,$gpu_load,$cpu0curfreq,$cpu1curfreq,$cpu2curfreq,$cpu3curfreq,$cpu4curfreq,$cpu5curfreq,$cpu6curfreq,$cpu7curfreq,$fps,$capacity,$user_cpu_usage,$system_cpu_usage,$total_cpu_usage" >> ./$current_time/system_info_$current_time.csv
done
echo "-------------finished--------------"
